var PUBLIC_PM = {
  // TODO  eg:"/brat"
  // prefixUrl: "file:///D:/Git/IdeaProjects/gucms/src/main/webapp",
  prefixUrl: window.location.origin + "",
  // prefixUrl: window.location.origin + "/brat",
  toolPrefixUrl: window.location.origin,
  userPrefixUrl: window.location.origin + "/sso"
};
var AJAX_CACHE = {
  userMessage: {},
  imgReturnArr: new Map(),
  projectsMsgObj: {}
};
if (!$.cookie().keyboardShortcut) {
  var keyboardShortcutObj = {};
  $.cookie("keyboardShortcut", JSON.stringify(keyboardShortcutObj), {expires: 360, path: "/"});
}
//TODO: debug
var millisecond = new Date().getTime();
var expiresTime = new Date(millisecond + 60 * 1000 * 10000000);
$.cookie('userName', "admin", {expires: expiresTime, path: "/"});
$.cookie('Authorization', "admin", {expires: expiresTime, path: "/"});
$.cookie('UserId', 1, {expires: expiresTime, path: "/"});
PUBLIC_PM.getCurrentDate = function () {
  var time = new Date();
  var year = time.getFullYear();
  var month = time.getMonth() + 1 > 9 ? time.getMonth() + 1 : "0" + (time.getMonth() + 1);
  var date = time.getDate() > 9 ? time.getDate() : "0" + time.getDate();
  var day = time.getDay();
  switch (day) {
    case 0:
      day = "星期日";
      break;
    case 1:
      day = "星期一";
      break;
    case 2:
      day = "星期二";
      break;
    case 3:
      day = "星期三";
      break;
    case 4:
      day = "星期四";
      break;
    case 5:
      day = "星期五";
      break;
    case 6:
      day = "星期六";
      break;
  }
  ;
  var hours = time.getHours() > 9 ? time.getHours() : "0" + time.getHours();
  var minutes = time.getMinutes() > 9 ? time.getMinutes() : "0" + time.getMinutes();
  var seconds = time.getSeconds() > 9 ? time.getSeconds() : "0" + time.getSeconds();
  return year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
};
// 当前UTC时间
PUBLIC_PM.getCurrentUTC = function () {
  var time = new Date();
  var year = time.getUTCFullYear();
  var month = time.getUTCMonth() + 1 > 9 ? time.getUTCMonth() + 1 : "0" + (time.getUTCMonth() + 1);
  var date = time.getUTCDate() > 9 ? time.getUTCDate() : "0" + time.getUTCDate();
  var hours = time.getUTCHours() > 9 ? time.getUTCHours() : "0" + time.getUTCHours();
  var minutes = time.getUTCMinutes() > 9 ? time.getUTCMinutes() : "0" + time.getUTCMinutes();
  var seconds = time.getUTCSeconds() > 9 ? time.getUTCSeconds() : "0" + time.getUTCSeconds();
  return year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
};
var currTimeZone = 8;
// 本地时间转化为UTC时间
PUBLIC_PM.localTime2UTC = function (local_datetime) {
  // 处理成为时间戳
  timestamp = new Date(Date.parse(local_datetime));
  timestamp = timestamp.getTime();
  timestamp = timestamp / 1000;
  var timestamp = timestamp - (currTimeZone * 60 * 60);
  // 时间戳转为时间
  var utc_datetime = new Date(parseInt(timestamp) * 1000);
  return (
    utc_datetime.getFullYear() +
    "-" +
    (utc_datetime.getMonth() + 1) +
    "-" +
    utc_datetime.getDate() +
    " " +
    utc_datetime.getHours() +
    ":" +
    utc_datetime.getMinutes() +
    ":" +
    utc_datetime.getSeconds()
  ).replace(/\b(\d)\b/g, function (a, b) {
    return "0" + b;
  });
};
// UTC时间转化为本地时间
PUBLIC_PM.utc2LocalTime = function (utc_datetime) {
  // 处理成为时间戳
  timestamp = new Date(Date.parse(utc_datetime));
  timestamp = timestamp.getTime();
  timestamp = timestamp / 1000;
  var timestamp = timestamp + (currTimeZone * 60 * 60);
  // 时间戳转为时间
  var local_datetime = new Date(parseInt(timestamp) * 1000);
  return (
    local_datetime.getFullYear() +
    "-" +
    (local_datetime.getMonth() + 1) +
    "-" +
    local_datetime.getDate() +
    " " +
    local_datetime.getHours() +
    ":" +
    local_datetime.getMinutes() +
    ":" +
    local_datetime.getSeconds()
  ).replace(/\b(\d)\b/g, function (a, b) {
    return "0" + b;
  });
};
function getUrlParam(name) {
  // 获取参数
  var url = window.location.search;
  // 正则筛选地址栏
  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  // 匹配目标参数
  var result = url.substr(1).match(reg);
  //返回参数值
  return result ? decodeURIComponent(result[2]) : null;
};
$.ajaxSetup({
  beforeSend: function (XMLHttpRequest) {
    if ($.cookie().Authorization && $.cookie().UserId) {
      XMLHttpRequest.setRequestHeader("Authorization", $.cookie().Authorization);
      XMLHttpRequest.setRequestHeader("UserId", $.cookie().UserId);
    } else {
      ShowMsg("未登录或无访问权限，请重新登录再试！");
      window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/login.html";
    }
  },
  success: function (data) {
    if (data.status !== "STATUS_SUCCESS") {
      ShowMsg(data.message);
    }
  },
  error: function (data) {
    console.log(data)
  },
  complete: function (xhr, status) {
    if (xhr.responseText && xhr.responseText.charAt(0) == "{") {
      if (JSON.parse(xhr.responseText).status && JSON.parse(xhr.responseText).status === "STATUS_NO_ACCESS") {
        $.cookie('Authorization', '', {expires: -1, path: "/"});
        $.cookie('UserId', '', {expires: -1, path: "/"});
        $.cookie("userName", '', {expires: -1, path: "/"});
        ShowMsg("未登录或无访问权限，请重新登录再试！");
        window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/login.html";
      }
    }
  }
});
//******公共方法start
// 退出功能
$("#git-nav-user .escBtn").click(function () {
  $.cookie('Authorization', '', {expires: -1, path: "/"});
  $.cookie('UserId', '', {expires: -1, path: "/"});
  $.cookie("userName", '', {expires: -1, path: "/"});
  window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/login.html";
})
//获取用户信息
getUserMessage($.cookie().UserId).then(function (message) {
  var message = message.content;
  AJAX_CACHE['userMessage'][message.id] = message;
  if (message) {
    if (message.nickname) {
      $('#navbar-notices .text').html(message.username + " / " + message.nickname);
    } else {
      $('#navbar-notices .text').html(message.username);
    }
    if (message.avatarUrl) {
      $('#git-nav-user img.avatar').show();
      $('#git-nav-user .avatar-box').hide();
      var $imgurl = PUBLIC_PM.prefixUrl + '/' + message.avatarUrl;
      if (AJAX_CACHE.imgReturnArr.get(message.id)) {
        $('#git-nav-user img.avatar').attr('src', AJAX_CACHE.imgReturnArr.get(message.id)[1].avatarUrl);
      } else {
        imgReturn($imgurl, message.id).then(function (dataUrl) {
          $('#git-nav-user img.avatar').attr('src', dataUrl);
        })
      }
    } else {
      $('#git-nav-user img.avatar').hide();
      $('#git-nav-user .avatar-box').show();
      $('#git-nav-user .avatar-box').text(generateLoginPassword(message.id, message.username));
      $('#git-nav-user .avatar-box').identicon5({size: 25});
    }
  }
});
//移除数组中指定元素
function arrRemove(arr, val) {
  var index = arr.indexOf(val);
  if (index > -1) {
    arr.splice(index, 1);
  }
};
//JSON 对象实现深拷贝
function jsonDeepClone(obj) {
  return JSON.parse(JSON.stringify(obj));
};
//关系动画，判断数据是否存在【不存在返回‘-’】
function isEmpty(obj) {
  if (typeof obj == "undefined" || obj == null || obj == "") {
    return '-';
  } else {
    return obj;
  }
};
//关系动画，判断数据是否存在【不存在返回空】
function isEmptyMessage(obj) {
  if (typeof obj == "undefined" || obj == null || obj == "") {
    return '';
  } else {
    return obj;
  }
};
function loadingBoxFn(box, bool) {
  //loading
  //box,添加位置，bool，true加载，false隐藏
  //eg:  loadingBoxFn('.serch-table-box', true);
  if (bool) {
    $(box).find('.loading-box').remove();
    $(box).append('<div class="loading-box" style="display: block"><img class="loading-img" src="img/loading.gif"></div>');
  } else {
    $(box).find('.loading-box').remove();
  }
};
//截取字符串 包含中文处理
//(串,长度,增加...)
function enAndCnSubString(str, len, hasDot) {
  var newLength = 0;
  var newStr = "";
  var chineseRegex = /[^\x00-\xff]/g;
  var singleChar = "";
  var strLength = str.replace(chineseRegex, "**").length;
  for (var i = 0; i < strLength; i++) {
    singleChar = str.charAt(i).toString();
    if (singleChar.match(chineseRegex) != null) {
      newLength += 2;
    } else {
      newLength++;
    }
    if (newLength > len) {
      break;
    }
    newStr += singleChar;
  }
  if (hasDot && strLength > len) {
    newStr += "...";
  }
  return newStr;
};
//过滤请求到的Json展示到列表，页面错乱
function filterAjaxJsonToHtml(str) {
  //去除，英文：' " ，
  // 特殊符号：< >
  str = str.toString()//数字转字符串
  str = str.replace(new RegExp(/,/g), '，');
  str = str.replace(new RegExp(/'/g), '‘');
  str = str.replace(new RegExp(/"/g), '“');
  str = str.replace(new RegExp(/</g), '&lt;');
  str = str.replace(new RegExp(/>/g), '&gt;');
  return str;
};
//自定义Map对象
// function Map () {
//   this.keys = new Array();
//   this.data = new Array();
//   this.put = function (key, value) {
//     if (this.data[key] == null) {
//       this.keys.push(value);
//     }
//     this.data[key] = value;
//   };
//   this.get = function (key) {
//     return this.data[key];
//   };
//   this.remove = function (key) {
//     this.keys.remove(key);
//     this.data[key] = null;
//   };
//   this.isEmpty = function () {
//     return this.keys.length == 0;
//   };
//   this.size = function () {
//     return this.keys.length;
//   };
// }
// //使用 例子
// var bb = new Map();
// bb.put("cc", dd);
// ShowMsg(bb.get("cc"));
// bb.put("cc", [{'id': 2}, {'id': 1}]);
// console.log(bb.data);
// console.log(bb.get(‘cc’));
/**统计页面
 * 在原有的时间上加一秒/分钟等
 * d : 字符串时间，格式为 yyyy-MM-dd HH:mm:ss
 * num : 秒
 * return : 返回 字符串 ，格式跟传入的相同
 */
function OriginalTimePlus(d, num) {
  var d = new Date(d.substring(0, 4),
    d.substring(5, 7) - 1,
    d.substring(8, 10),
    d.substring(11, 13),
    d.substring(14, 16),
    d.substring(17, 19));
  d.setTime(d.getTime() + num * 1000);
  //console.log(d.toLocaleString());
  var year = d.getFullYear();
  var month = d.getMonth() + 1 > 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1);
  var date = d.getDate() > 9 ? d.getDate() : "0" + d.getDate();
  var day = d.getDay();
  var hours = d.getHours() > 9 ? d.getHours() : "0" + d.getHours();
  var minutes = d.getMinutes() > 9 ? d.getMinutes() : "0" + d.getMinutes();
  var seconds = d.getSeconds() > 9 ? d.getSeconds() : "0" + d.getSeconds();
  return year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds
};
// var minute = dateAdd('2017-08-24 15:58:15', 60); //加一秒钟
// console.log('加一分钟' + minute);
//*****公共方法end
//图片地址获取-添加权限
function imgReturn($imgurl, $userId) {
  var def = $.Deferred();
  var xhr = new XMLHttpRequest();
  xhr.open('GET', $imgurl, true);
  xhr.responseType = 'blob'; //so you can access the response like a normal URL
  xhr.onload = function (e) {
    if (this.status == 200) {
      var $src = URL.createObjectURL(this.response); //create <img> with src set to the blob
      AJAX_CACHE.imgReturnArr.put($userId, [{'id': $userId}, {'avatarUrl': $src}]);
      def.resolve($src);
      def.promise($src);
    }
  };
  xhr.setRequestHeader("Authorization", $.cookie().Authorization);
  xhr.setRequestHeader("UserId", $.cookie().UserId);
  xhr.send();
  return def;
}
// 项目title切换
var projectId = getUrlParam("projectId") == null ? "" : getUrlParam("projectId");
var projectTitle = getUrlParam("projectTitle") == null ? "全局唯一性内容管理系统" : getUrlParam("projectTitle");
$("#git-header-nav #project-title").text(projectTitle);
if (projectTitle != "快速标注工具平台") {
  $("#dashboard-sidebar #document-nav").css("display", "block");
  $("#dashboard-sidebar #search-nav").css("display", "block");
  $("#dashboard-sidebar #statistics-nav").css("display", "block");
  $("#dashboard-sidebar #tool-nav").css("display", "block");
  $(".ent-projects-header-menu .crumb-box .proTitle").text(projectTitle);
} else {
  if ($("#dashboard-sidebar #task-nav.active").length == 1) {
    $(".ent-projects-header-menu .crumb-box i").eq(0).remove();
    $(".ent-projects-header-menu .crumb-box .proTitle").remove();
  }
}
//点击页面跳转
// 数据类别
// $("#categoryHtml").click(function () {
//     window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/index.html";
// });
// // 文献
// $("#literatureHtml").click(function () {
//     window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/literatureHtml.html";
// });
// // SPAN
// $("#spanHtml").click(function () {
//     window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/spanHtml.html";
// });
// // pdfHtml
// $("#pdfHtml").click(function () {
//     window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/pdfHtml.html";
// });
// // searchHtml
// $("#searchHtml").click(function () {
//     window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/searchHtml.html";
// });
// header 部分
var headerProjectMessageListStatus = 1;
var headerTaskMessageListStatus = 1;
// 项目消息
function headerProjectMessageList(hoverUpdateData) {
  if (headerProjectMessageListStatus != 1) {
    return;
  }
  headerProjectMessageListStatus = 0;
  headerProjectMessageListData(0, 5, hoverUpdateData);
};
// 项目消息列表模板渲染
function headerProjectMessageListTemeplate(data) {
  $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project").empty();
  var targetParent = $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project");
  var count = 0;
  $.each(data, function (k, v) {
    var projectStatusCreateTime = v.projectStatusCreateTime;
    var projectId = v.projectId;
    var projectTitle = v.projectTitle;
    var projectStatus = v.projectStatus;
    var str = $(`
			<li class="project-msg-item classify noti">
				<a class="text" href="taskList.html?type=manage&projectId=${projectId}&projectTitle=${projectTitle}">
					<i class="iconfont iconfont-status" style="font-size:14px;padding-top:1px;vertical-align: bottom;"></i> 
					${projectStatus} ：
					<span title=${projectTitle}>${projectTitle}</span>
				</a>
				<span class="time">${PUBLIC_PM.utc2LocalTime(projectStatusCreateTime)}</span>
			</li>
		`)
    switch (projectStatus) {
      case "开始":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-1");
        str.find(".iconfont.iconfont-status").css("color", "rgb(254, 188, 8)");
        break;
      case "延期":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-23");
        str.find(".iconfont.iconfont-status").css("color", "rgb(254, 115, 0)");
        break;
      case "挂起":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-21");
        str.find(".iconfont.iconfont-status").css("color", "rgb(74, 144, 226)");
        break;
      case "关闭":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-7");
        str.find(".iconfont.iconfont-status").css("color", "rgb(236, 0, 25)");
        break;
    }
    targetParent.append(str);
    count += 1;
    if (count === data.length) {
      headerProjectMessageListStatus = 1;
    }
  })
};
// 项目消息数据请求
function headerProjectMessageListData(page, size, hoverUpdateData) {
  getProjectStatuaHistory(page, size, -1).then(function (data) {
    var data = data.content.content;
    if (data.length > 0) {
      $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-blank").hide();
      var targetEle = $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project");
      if ($.cookie().headerProjectMessage && $.isEmptyObject(JSON.parse($.cookie().headerProjectMessage)) == false) {
        var obj = JSON.parse($.cookie().headerProjectMessage);
        $.each(data, function (k, v) {
          if (!obj[v.projectId] || obj[v.projectId].indexOf(v.createTime) == -1) {
            // 小红点
            if (!hoverUpdateData) {
              $("#git-header-nav #notice-dropdown .remind-button .notice-count").show();
              $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .projectTab .notice-count").show();
            }
            var obj1 = {};
            $.each(data, function (k1, v1) {
              obj1[v1.projectId] = obj1[v1.projectId] || [];
              obj1[v1.projectId].push(v1.createTime);
            })
            $.cookie("headerProjectMessage", JSON.stringify(obj1), {path: "/"});
            headerProjectMessageListTemeplate(data);
            return false;
          } else if (targetEle.text() == "") {
            var obj1 = {};
            $.each(data, function (k1, v1) {
              obj1[v1.projectId] = obj1[v1.projectId] || [];
              obj1[v1.projectId].push(v1.createTime);
            })
            $.cookie("headerProjectMessage", JSON.stringify(obj1), {path: "/"});
            headerProjectMessageListTemeplate(data);
            return false;
          } else {
            if (k == data.length - 1) {
              headerProjectMessageListStatus = 1;
            }
          }
        })
      } else {
        var obj = {};
        $.each(data, function (k, v) {
          obj[v.projectId] = obj[v.projectId] || [];
          obj[v.projectId].push(v.createTime);
        })
        $.cookie("headerProjectMessage", JSON.stringify(obj), {path: "/"});
        headerProjectMessageListTemeplate(data);
      }
    } else {
      if ($(".tab.active").hasClass("projectTab")) {
        $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project").hide();
        $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-blank").show();
        headerProjectMessageListStatus = 1;
      }
    }
  })
};
// 任务消息
function headerTaskMessageList(hoverUpdateData) {
  if (headerTaskMessageListStatus != 1) {
    return;
  }
  headerTaskMessageListStatus = 0;
  headerTaskMessageListData(0, 5, hoverUpdateData);
};
// 任务消息列表模板渲染
function headerTaskMessageListTemeplate(data) {
  $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task").empty();
  var targetParent = $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task");
  var count = 0;
  $.each(data, function (k, v) {
    var taskStatusCreateTime = v.taskStatusCreateTime;
    var projectId = v.projectId;
    var taskId = v.taskId;
    var taskTitle = v.taskTitle;
    var taskStatus = v.taskStatus;
    var str = $(`
                <li class="task-msg-item classify noti" task-id=${taskId} project-id=${projectId}>
                    <a class="text">
                        <i class="iconfont iconfont-status" style="font-size:14px;padding-top:1px;vertical-align: bottom;"></i> 
                        ${taskStatus} ：
                        <span title="${taskTitle}">${taskTitle}</span>
                    </a>
                    <span class="time">${PUBLIC_PM.utc2LocalTime(taskStatusCreateTime)}</span>
                </li>
                `)
    switch (taskStatus) {
      case "已排期":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-6");
        str.find(".iconfont.iconfont-status").css("color", "rgb(254, 188, 8)");
        break;
      case "进行中":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-10");
        str.find(".iconfont.iconfont-status").css("color", "rgb(29, 186, 174)");
        break;
      case "挂起":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-21");
        str.find(".iconfont.iconfont-status").css("color", "rgb(74, 144, 226)");
        break;
      case "延期":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-23");
        str.find(".iconfont.iconfont-status").css("color", "rgb(254, 115, 0)");
        break;
      case "完成":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-22");
        str.find(".iconfont.iconfont-status").css("color", "rgb(140, 146, 164)");
        break;
      case "取消":
        str.find(".iconfont.iconfont-status").addClass("icon-task-state-7");
        str.find(".iconfont.iconfont-status").css("color", "rgb(236, 0, 25)");
        break;
    }
    targetParent.append(str);
    count += 1;
    if (count == data.length) {
      headerTaskMessageListStatus = 1;
    }
  });
};
// 点击任务消息跳转到详情页
$(".notice-dropdown-panel-container").on("click", "li", function () {
  var taskId = $(this).attr("task-id");
  var projectId = $(this).attr("project-id");
  taskMsg(taskId).then(function (taskMsgData) {
    var documentId = taskMsgData.taskDocumentsById[0] ? taskMsgData.taskDocumentsById[0].documentId : "";
    if (AJAX_CACHE.projectsMsgObj[projectId]) {
      var projectMsgData = AJAX_CACHE.projectsMsgObj[projectId];
      var projectTitle = projectMsgData.title;
      window.open(`./taskOperation.html?type=manage&projectId=${projectId}&projectTitle=${projectTitle}&documentId=${documentId}&taskId=${taskId}&taskType=update`);
    } else {
      projectMsg(projectId).then(function (projectMsgData) {
        AJAX_CACHE.projectsMsgObj[projectId] = projectMsgData;
        var projectTitle = projectMsgData.title;
        window.open(`./taskOperation.html?type=manage&projectId=${projectId}&projectTitle=${projectTitle}&documentId=${documentId}&taskId=${taskId}&taskType=update`);
      })
    }
  });
})
// 任务消息列表数据请求
function headerTaskMessageListData(page, size, hoverUpdateData) {
  getTaskStatuaHistory(page, size, -1).then(function (data) {
    var data = data.content.content;
    if (data.length > 0) {
      $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-blank").hide();
      var targetEle = $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task");
      if ($.cookie().headerTaskMessage && $.isEmptyObject(JSON.parse($.cookie().headerTaskMessage)) == false) {
        var obj = JSON.parse($.cookie().headerTaskMessage);
        $.each(data, function (k, v) {
          if (!obj[v.taskId] || obj[v.taskId].indexOf(v.createTime) == -1) {
            // 小红点
            if (!hoverUpdateData) {
              $("#git-header-nav #notice-dropdown .remind-button .notice-count").show();
              $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .taskTab .notice-count").show();
            }
            var obj1 = {};
            $.each(data, function (k1, v1) {
              obj1[v1.taskId] = obj1[v1.taskId] || [];
              obj1[v1.taskId].push(v1.createTime);
            })
            $.cookie("headerTaskMessage", JSON.stringify(obj1), {path: "/"});
            headerTaskMessageListTemeplate(data);
            return false;
          } else if (targetEle.text() == "") {
            var obj1 = {};
            $.each(data, function (k1, v1) {
              obj1[v1.taskId] = obj1[v1.taskId] || [];
              obj1[v1.taskId].push(v1.createTime);
            })
            $.cookie("headerTaskMessage", JSON.stringify(obj1), {path: "/"});
            headerTaskMessageListTemeplate(data);
            return false;
          } else {
            if (k == data.length - 1) {
              headerTaskMessageListStatus = 1;
            }
          }
        })
      } else {
        var obj = {};
        $.each(data, function (k, v) {
          obj[v.taskId] = obj[v.taskId] || [];
          obj[v.taskId].push(v.createTime);
        })
        $.cookie("headerTaskMessage", JSON.stringify(obj), {path: "/"});
        headerTaskMessageListTemeplate(data);
      }
    } else {
      if (!$(".tab.active").hasClass("projectTab")) {
        $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task").hide();
        $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-blank").show();
        headerTaskMessageListStatus = 1;
      }
    }
  })
};
// 页面加载自动获取消息列表
function initHeaderMessage() {
  headerProjectMessageList();
  headerTaskMessageList();
  IntervalHeaderMessage();
};
// initHeaderMessage();
// 消息列表20分钟自动刷新
function IntervalHeaderMessage() {
  clearInterval(time);
  var time = setInterval(function () {
    headerProjectMessageListStatus = 1;
    headerTaskMessageListStatus = 1;
    headerProjectMessageList();
    headerTaskMessageList();
  }, 1000 * 60 * 20);
}
// 鼠标hover事件获取消息列表
$("#git-header-nav #notice-dropdown").hover(function () {
  $(this).find(".notice-dropdown-panel.menu").show();
  if ($(this).find(".taskTab .notice-count").css("display") == "block") {
    $(this).find(".tab").removeClass("active");
    $(this).find(".taskTab").addClass("active");
  } else if ($(this).find(".projectTab .notice-count").css("display") == "block") {
    $(this).find(".tab").removeClass("active");
    $(this).find(".projectTab").addClass("active");
  }
  var hoverUpdateData = true;
  if ($(".tab.active").hasClass("projectTab")) {
    headerProjectMessageList(hoverUpdateData);
    $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task").hide();
    $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project").show();
  } else {
    headerTaskMessageList(hoverUpdateData);
    $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project").hide();
    $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task").show();
  }
}, function () {
  $(this).find(".notice-dropdown-panel.menu").hide();
});
$("#git-header-nav .notice-list-project").hover(function () {
  $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .projectTab .notice-count").hide();
  if ($("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .taskTab .notice-count").css("display") == "none") {
    $("#git-header-nav #notice-dropdown .remind-button .notice-count").hide();
  }
});
$("#git-header-nav .notice-list-task").hover(function () {
  $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .taskTab .notice-count").hide();
  if ($("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .projectTab .notice-count").css("display") == "none") {
    $("#git-header-nav #notice-dropdown .remind-button .notice-count").hide();
  }
});
$("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .tab").hover(function () {
  if ($(this).hasClass("projectTab")) {
    $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .projectTab .notice-count").hide();
    if ($("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .taskTab .notice-count").css("display") == "none") {
      $("#git-header-nav #notice-dropdown .remind-button .notice-count").hide();
    }
  } else {
    $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .taskTab .notice-count").hide();
    if ($("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .projectTab .notice-count").css("display") == "none") {
      $("#git-header-nav #notice-dropdown .remind-button .notice-count").hide();
    }
  }
});
$("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .tab").click(function () {
  if (!$(this).hasClass("active")) {
    $(this).addClass("active");
    $(this).siblings().removeClass('active');
    if ($(this).hasClass("projectTab")) {
      $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project").show();
      $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task").hide();
      $("#git-header-nav #notice-dropdown .remind-button .notice-count").hide();
      $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .projectTab .notice-count").hide();
      // headerProjectMessageList();
    } else {
      $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-project").hide();
      $("#git-header-nav #notice-dropdown.empty .notice-dropdown-panel-container .notice-list-task").show();
      $("#git-header-nav #notice-dropdown .remind-button .notice-count").hide();
      $("#git-header-nav #notice-dropdown .notice-dropdown-panel-header .taskTab .notice-count").hide();
      // headerTaskMessageList();
    }
  }
});
$("#git-header-nav #notice-dropdown .load-all").click(function () {
  $("#git-header-nav #notice-dropdown .notice-count").hide();
  if ($(".tab.active").hasClass("projectTab")) {
    window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/projectMessageList.html";
  } else {
    window.location.href = PUBLIC_PM.prefixUrl + "/projectManagement/taskMessageList.html";
  }
});
$("#git-nav-user").hover(function () {
  $(this).find(".menu").show();
}, function () {
  $(this).find(".menu").hide();
});
// 隐藏二级导航目录
$(".ent-resource-main .ent-resource-sidebar-toggle i").click(function () {
  var parent = $(this).parents(".ent-resource");
  if ($(parent).hasClass("sidebar-hidden")) {
    $(parent).removeClass("sidebar-hidden");
    $(this).removeClass("right");
    $(this).addClass("left");
  } else {
    $(parent).addClass("sidebar-hidden");
    $(this).removeClass("left");
    $(this).addClass("right");
  }
});
// 根据name查找数组对象中对应的id
function searchIdFromName(data, name) {
  var id = "";
  $.each(data, function (k, v) {
    if (v.name == name) {
      id = v.id;
      return;
    }
  })
  return id;
};
function getArrDifference(arr1, arr2) {
  //取出两个数组的不同元素
  return arr1.concat(arr2).filter(function (v, i, arr) {
    return arr.indexOf(v) === arr.lastIndexOf(v);
  });
}
// 根据id查找name
function searchNameFromId(data, id) {
  var name = "";
  $.each(data, function (k, v) {
    if (v.id == id) {
      name = v.name;
      return;
    }
  })
  return name;
};
//数组中添加不重复元素
var addArrData = function (arr, val) {
  if ($.inArray(val, arr) < 0) {
    arr.push(val);
  }
};
// ******静态数据 start
PUBLIC_PM.totalStausList = [{
  "id": 1,
  "name": "已排期",
  "description": "任务已经创建，但是任务承担者尚未改变任务状态。这种情况可能是因为任务的前置条件没有满足。",
  "createTime": "2019-09-09T00:57:52.000+0000"
},
  {
    "id": 2,
    "name": "进行中",
    "description": "任务正在进行。",
    "createTime": "2019-09-09T00:57:52.000+0000"
  },
  {
    "id": 3,
    "name": "挂起",
    "description": "由于任务进行的部分条件发生意外得不到满足，任务暂停进行。",
    "createTime": "2019-09-09T00:57:52.000+0000"
  },
  {
    "id": 4,
    "name": "延期",
    "description": "任务时间表延宕。",
    "createTime": "2019-09-09T00:57:52.000+0000"
  },
  {
    "id": 5,
    "name": "完成",
    "description": "任务已经完成。",
    "createTime": "2019-09-09T00:57:52.000+0000"
  },
  {
    "id": 6,
    "name": "取消",
    "description": "任务被取消。",
    "createTime": "2019-09-09T00:57:52.000+0000"
  }
];
PUBLIC_PM.totalRoleList = [{
  "id": 1,
  "name": "任务审核人",
  "description": "可以更改任务内容和任务状态",
  "createTime": "2019-09-05T03:19:28.000+0000"
},
  {
    "id": 2,
    "name": "任务完成人",
    "description": "可以完成任务",
    "createTime": "2019-09-05T03:19:28.000+0000"
  }
];
PUBLIC_PM.projectStausList = [{
  "id": 1,
  "name": "开始",
  "createTime": "2019-09-05T02:33:23.000+0000"
},
  {
    "id": 2,
    "name": "延期",
    "createTime": "2019-09-05T02:33:23.000+0000"
  },
  {
    "id": 3,
    "name": "挂起",
    "createTime": "2019-09-05T02:33:23.000+0000"
  },
  {
    "id": 4,
    "name": "关闭",
    "createTime": "2019-09-05T02:33:23.000+0000"
  }
];
PUBLIC_PM.projectRoleList = [{
  "id": 1,
  "name": "负责人",
  "description": "对项目的最终成果负责，也因此具有对项目的最高权限。",
  "createTime": "2019-09-05T03:17:50.000+0000"
},
  {
    "id": 2,
    "name": "项目助理",
    "description": "除了不能更改项目状态和创建项目外，具有所有其他项目管理权限。",
    "createTime": "2019-09-05T03:17:50.000+0000"
  },
  {
    "id": 3,
    "name": "任务负责人",
    "description": "可以创建任务。",
    "createTime": "2019-09-05T03:17:50.000+0000"
  },
  {
    "id": 4,
    "name": "任务承担者",
    "description": "不能创建任务，但是可以浏览并完成任务。",
    "createTime": "2019-09-05T03:17:50.000+0000"
  }
];
// ******静态数据 end
// ******通过中转，获取sso接口
//编辑个人资料-文件路径
function uploadImgFile($file) {
  var def = $.Deferred();
  $.ajax({
    type: "POST",
    url: PUBLIC_PM.prefixUrl + "/file-api/uploadImg",
    data: $file,
    // data: JSON.stringify(data),
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    processData: false,
    contentType: false,
    // cache: false,
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise(data);
      }
    }
  });
  return def;
};
//编辑个人资料-message
function updateUserMessage($data) {
  var def = $.Deferred();
  $.ajax({
    type: "POST",
    url: PUBLIC_PM.userPrefixUrl + "/sso-api/update",
    // data: $data,
    data: JSON.stringify($data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise(data);
      }
    }
  });
  return def;
};
//根据ID获取用户信息
function getUserMessage($userId) {
  var def = $.Deferred();
  $.ajax({
    type: "GET",
    url: PUBLIC_PM.userPrefixUrl + "/sso-api/" + $userId,
    // data:data,
    // data: JSON.stringify(data),
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise(data);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    }
  });
  return def;
};
//根据ID获取用户信息---同步请求
function getUserMessageSync($userId) {
  var def = $.Deferred();
  $.ajax({
    type: "GET",
    url: PUBLIC_PM.userPrefixUrl + "/sso-api/" + $userId,
    async: false,
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise(data);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    }
  });
  return def;
};
// 根据用户名获取用户信息
function getUserMessageByName(userName) {
  var getUserMessageByName = $.Deferred();
  $.ajax({
    type: "GET",
    url: PUBLIC_PM.userPrefixUrl + "/sso-api/findByName?userName=" + userName,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        getUserMessageByName.resolve(data)
        getUserMessageByName.promise(data);
      } else {
        ShowMsg("用户不存在或用户名输入不正确！");
      }
    }
  });
  return getUserMessageByName;
};
//更改密码
function changePassword($oldPassword, $userPassword) {
  var def = $.Deferred();
  $.ajax({
    type: "POST",
    url: PUBLIC_PM.userPrefixUrl + "/sso-api/changePassword/",
    data: {
      'oldPassword': $oldPassword,
      'userPassword': $userPassword
    },
    // data: JSON.stringify(data),
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise(data);
      } else if (data.status == "STATUS_FAIL") {
        ShowMsg('原密码错误！')
      }
    }
  });
  return def;
};
// ******通过中转，获取sso接口end
// ******任务start
// 我发布的任务列表with状态
function myIssueTaskWithStatus(page, size, statusId) {
  var myIssueTaskWithStatus = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/task-api/myTaskWithStatus/" + statusId + "?page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myIssueTaskWithStatus.resolve(data)
        myIssueTaskWithStatus.promise();
      }
    },
    error: function (data) {
      myIssueTaskWithStatus.reject(data)
      myIssueTaskWithStatus.promise(data);
    }
  });
  return myIssueTaskWithStatus;
};
// 项目中我发布的任务列表with状态
function myIssueTaskWithStatusAndProject(page, size, statusId, projectId) {
  var myIssueTaskWithStatusAndProject = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/task-api/myTaskWithStatusAndProject?statusId=" + statusId + "&projectId=" + projectId + "&page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myIssueTaskWithStatusAndProject.resolve(data)
        myIssueTaskWithStatusAndProject.promise();
      }
    },
    error: function (data) {
      myIssueTaskWithStatusAndProject.reject(data)
      myIssueTaskWithStatusAndProject.promise(data);
    }
  });
  return myIssueTaskWithStatusAndProject;
};
// 我审核的、我执行的任务列表with状态
function myAttendanceTaskWithRoleAndStatus(page, size, roleId, statusId) {
  var myAttendanceTaskWithRoleAndStatus = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/task-api/myAttendanceTaskWithRoleAndStatus?roleId=" + roleId + "&statusId=" + statusId + "&page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myAttendanceTaskWithRoleAndStatus.resolve(data)
        myAttendanceTaskWithRoleAndStatus.promise();
      }
    },
    error: function (data) {
      myAttendanceTaskWithRoleAndStatus.reject(data)
      myAttendanceTaskWithRoleAndStatus.promise(data);
    }
  });
  return myAttendanceTaskWithRoleAndStatus;
};
// 项目中我审核的、我执行的任务列表with状态
function myAttendanceTaskWithRoleAndStatusAndProject(page, size, roleId, statusId, projectId) {
  var myAttendanceTaskWithRoleAndStatusAndProject = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/task-api/myAttendanceTaskWithRoleAndStatusAndProject?roleId=" + roleId + "&statusId=" + statusId + "&projectId=" + projectId + "&page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myAttendanceTaskWithRoleAndStatusAndProject.resolve(data)
        myAttendanceTaskWithRoleAndStatusAndProject.promise();
      }
    },
    error: function (data) {
      myAttendanceTaskWithRoleAndStatusAndProject.reject(data)
      myAttendanceTaskWithRoleAndStatusAndProject.promise(data);
    }
  });
  return myAttendanceTaskWithRoleAndStatusAndProject;
};
// 项目中我所有的任务列表with状态
function myAllTaskWithStatusAndProject(page, size, statusId, projectId) {
  var myAllTaskWithStatusAndProject = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/task-api/projectWithStatus/" + projectId,
    data: {
      "statusId": statusId,
      "page": page,
      "size": size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myAllTaskWithStatusAndProject.resolve(data)
        myAllTaskWithStatusAndProject.promise();
      }
    },
    error: function (data) {
      myAllTaskWithStatusAndProject.reject(data)
      myAllTaskWithStatusAndProject.promise(data);
    }
  });
  return myAllTaskWithStatusAndProject;
};
// 新建任务
function createTask(data) {
  var createTask = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/task-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        createTask.resolve(data)
        createTask.promise();
      } else {
        ShowMsg("您无权限！");
      }
    },
    error: function (data) {
      ShowMsg("您填写的文档ID可能不存在，请查证后重新填写并提交！");
    }
  });
  return createTask;
};
// 成员列表自动分配任务
function autoAssignTaskFromMemberList(data, documentCount) {
  var ref = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/task-api/autoAssignDocuments/?documentCount=" + documentCount,
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data)
        ref.promise();
      } else {
        ShowMsg("您无权限！");
      }
    },
    error: function (data) {
      ShowMsg("您没权限！");
    }
  });
  return ref;
};
// 编辑任务
function updateTask(data) {
  var updateTask = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/task-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        updateTask.resolve(data)
        updateTask.promise();
      } else {
        ShowMsg("您没有权限！");
      }
    }
  });
  return updateTask;
};
// 增加任务历史状态
function createTaskStatus(data) {
  var createTaskStatus = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/taskStatusHistory-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      createTaskStatus.resolve(data)
      createTaskStatus.promise();
    }
  });
  return createTaskStatus;
};
// 获取任务历史状态
function getTaskStatuaHistory(page, size, taskId) {
  var getTaskStatuaHistory = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/taskStatusHistory-api/?taskId=" + taskId + "&page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        getTaskStatuaHistory.resolve(data)
        getTaskStatuaHistory.promise();
      }
    }
  });
  return getTaskStatuaHistory;
};
// 获取当前任务中所有成员及角色
function getTaskUser(taskId, page, size) {
  var getTaskUser = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/taskUser-api/",
    data: {
      taskId: taskId,
      page: page,
      size: size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        getTaskUser.resolve(data)
        getTaskUser.promise();
      }
    }
  });
  return getTaskUser;
};
// 增加任务审核人、执行人
function createTaskUser(data) {
  var createTaskUser = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/taskUser-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        createTaskUser.resolve(data)
        createTaskUser.promise();
      }
    }
  });
  return createTaskUser;
};
// 删除任务审核人、执行人
function deleteTaskUser(data) {
  var deleteTaskUser = $.Deferred();
  $.ajax({
    type: "delete",
    url: PUBLIC_PM.prefixUrl + "/taskUser-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        deleteTaskUser.resolve(data)
        deleteTaskUser.promise();
      }
    }
  });
  return deleteTaskUser;
};
// 查看任务详情
function taskMsg(taskId) {
  var taskMsg = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/task-api/" + taskId + "?page=0&size=1",
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        taskMsg.resolve(data.content)
        taskMsg.promise();
      }
    }
  });
  return taskMsg;
};
// 自动申请任务
function autoApplyTask(projectId) {
  var ref = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/taskUser-api/applyForCompleter/" + projectId,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data.content)
        ref.promise();
      }
    },
    error: function () {
      ShowMsg("申请不成功！");
    }
  });
  return ref;
};
// ******任务end
// ******文档start
// 文档列表--项目下
function documentListByProject(page, size, projectId) {
  var documentListByProject = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/document-api/byProject/" + projectId + "?page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        documentListByProject.resolve(data)
        documentListByProject.promise();
      }
    },
    error: function (data) {
      documentListByProject.reject(data)
      documentListByProject.promise(data);
    }
  });
  return documentListByProject;
};
// 创建文档--项目下
function createDocument(data) {
  var createDocument = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/document-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        createDocument.resolve(data)
        createDocument.promise();
      }
    }
  });
  return createDocument;
};
// 删除文档
function deleteDocument(documentId) {
  var def = $.Deferred();
  $.ajax({
    type: "delete",
    url: PUBLIC_PM.prefixUrl + "/document-api/" + documentId,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise();
      }
    }
  });
  return def;
};
// 文档信息
function documentMsg(documentId) {
  var documentMsg = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/document-api/" + documentId,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        documentMsg.resolve(data)
        documentMsg.promise();
      }
    }
  });
  return documentMsg;
};
// 使用工具标注文档--标注任务
function documentAnnotatedWithTool(instanceId, documentId) {
  var ref = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/document-api/annotatedWithTool?projectToolInstanceId=" + instanceId,
    data: {
      documentId: documentId
    },
    dataType: "json",
    success: function (data) {
      ref.resolve(data)
      ref.promise();
    }
  });
  return ref;
};
// 使用工具标注文档--模拟任务
function documentLearnFrom(toolId, projectId) {
  var documentLearnFrom = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/document-api/learnFrom",
    data: {
      toolId: toolId,
      projectId: projectId
    },
    dataType: "json",
    success: function (data) {
      documentLearnFrom.resolve(data)
      documentLearnFrom.promise();
    }
  });
  return documentLearnFrom;
};
// 文档列表下载
function documentDownload(projectId, begin, size) {
  var documentDownload = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/document-api/export?projectId=" + projectId + "&begin=" + begin + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      documentDownload.resolve(data)
      documentDownload.promise();
    }
  });
  return documentDownload;
};
// 文档列表下载Ann包
function documentDownloadAnnZip(projectId, begin, size) {
  var url = PUBLIC_PM.prefixUrl + "/document-api/exportWithAnn?projectId=" + projectId + "&begin=" + begin + "&size=" + size;
  var xhr = new XMLHttpRequest();
  xhr.open('GET', url, true);
  xhr.setRequestHeader("Authorization", $.cookie().Authorization)
  xhr.setRequestHeader("UserId", $.cookie().UserId)
  xhr.responseType = "blob";    // 返回类型blob
  // 定义请求完成的处理函数，请求前也可以增加加载框/禁用下载按钮逻辑
  xhr.onload = function () {
    // 请求完成
    if (this.status === 200) {
      var blob = this.response;
      var reader = new FileReader();
      reader.readAsDataURL(blob);    // 转换为base64，可以直接放入a表情href
      reader.onload = function (e) {
        // 转换完成，创建一个a标签用于下载
        var a = document.createElement('a');
        a.download = 'Ann.zip';
        a.href = e.target.result;
        $("body").append(a);    // 修复firefox中无法触发click
        a.click();
        $(a).remove();
        $(".documenDownloadBox .documenDownloadLoading .loading-box").hide();
      }
    }
  };
  xhr.send();
};
// ******文档end
// ******项目start
// 查看项目基本信息
function projectMsg(projectId, async) {
  var projectMsg = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/project-api/" + Number(projectId),
    data: {},
    dataType: "json",
    async: async || false,
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        projectMsg.resolve(data.content)
        projectMsg.promise();
      }
    },
    error: function (data) {
      projectMsg.reject(data)
      projectMsg.promise(data);
    }
  });
  return projectMsg;
};
// 我创建的项目列表包含状态
function myCreatedProjectListWithStatus(page, size, statusId) {
  var myCreatedProjectListWithStatus = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/project-api/myProjectWithStatus/" + statusId,
    data: {
      page: page,
      size: size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myCreatedProjectListWithStatus.resolve(data)
        myCreatedProjectListWithStatus.promise();
      }
    }
  });
  return myCreatedProjectListWithStatus;
};
// 我创建的项目列表包含状态--聚合视图
function myCreatedProjectListWithStatusAggregatedView(page, size, statusId) {
  var ref = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/project-api/myProjectAggregatedViewWithStatus/" + statusId,
    data: {
      page: page,
      size: size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data)
        ref.promise();
      }
    }
  });
  return ref;
};
// 我参与的项目列表包含状态
function myAttendanceProjectListWithStatus(page, size, statusId) {
  var myAttendanceProjectListWithStatus = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/project-api/myAttendanceWithStatus/" + statusId,
    data: {
      page: page,
      size: size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        myAttendanceProjectListWithStatus.resolve(data)
        myAttendanceProjectListWithStatus.promise();
      }
    }
  });
  return myAttendanceProjectListWithStatus;
};
// 我参与的项目列表包含状态--聚合视图
function myAttendanceProjectListWithStatusAggregatedView(page, size, statusId) {
  var ref = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/project-api/myAttendanceProjectAggregatedViewWithStatus/" + statusId,
    data: {
      page: page,
      size: size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data)
        ref.promise();
      }
    }
  });
  return ref;
};
// 新建项目
function createProject(data) {
  var createProject = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/project-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        createProject.resolve(data)
        createProject.promise();
      }
    }
  });
  return createProject;
};
// 添加项目历史状态
function projectStatuaHistory(data) {
  var projectStatuaHistory = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/projectStatusHistory-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        projectStatuaHistory.resolve(data)
        projectStatuaHistory.promise();
      }
    }
  });
  return projectStatuaHistory;
};
// 获取项目历史状态
function getProjectStatuaHistory(page, size, projectId) {
  var getProjectStatuaHistory = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/projectStatusHistory-api/?projectId=" + projectId + "&page=" + page + "&size=" + size,
    data: {},
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        getProjectStatuaHistory.resolve(data)
        getProjectStatuaHistory.promise();
      }
    }
  });
  return getProjectStatuaHistory;
};
// 获取项目成员列表
function getProjectUser(page, size, projectId) {
  var getProjectUser = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/projectUser-api/",
    data: {
      "projectId": projectId,
      "page": page,
      "size": size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        getProjectUser.resolve(data)
        getProjectUser.promise();
      }
    },
    error: function (data) {
      getProjectUser.reject(data)
      getProjectUser.promise(data);
    }
  });
  return getProjectUser;
};
// 添加项目成员
function addProjectUser(data) {
  var addProjectUser = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/projectUser-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      addProjectUser.resolve(data)
      addProjectUser.promise();
    }
  });
  return addProjectUser;
};
// 批量添加成员
function batchAddProjectUser(data) {
  var ref = $.Deferred();
  $.ajax({
    type: "put",
    url: PUBLIC_PM.prefixUrl + "/projectUser-api/withBatch",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      ref.resolve(data)
      ref.promise();
    }
  });
  return ref;
};
// 删除项目成员
function delProjectUser(data) {
  var delProjectUser = $.Deferred();
  $.ajax({
    type: "DELETE",
    url: PUBLIC_PM.prefixUrl + "/projectUser-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      delProjectUser.resolve(data)
      delProjectUser.promise();
    }
  });
  return delProjectUser;
};
// 编辑项目
function editProject(data) {
  var def = $.Deferred();
  $.ajax({
    type: "POST",
    url: PUBLIC_PM.prefixUrl + "/project-api/",
    // data:data,
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise();
      }
    }
  });
  return def;
};
// ******项目end
// ******tool  start
// 获取tool列表
function toolList(page, size) {
  var toolList = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/tool-api/",
    data: {
      page: page,
      size: size
    },
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        toolList.resolve(data.content);
        toolList.promise();
      }
    }
  });
  return toolList;
};
// 获取tool信息
function toolMsg(toolId) {
  var toolMsg = $.Deferred();
  $.ajax({
    type: "get",
    async: false,
    url: PUBLIC_PM.prefixUrl + "/tool-api/" + toolId,
    data: {},
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        toolMsg.resolve(data.content);
        toolMsg.promise();
      }
    }
  });
  return toolMsg;
};
// 项目关联tool
function projectTool(projectId, toolIds) {
  var projectTool = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/projectTool-api/" + projectId,
    // data:data,
    data: JSON.stringify(toolIds),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        projectTool.resolve(data);
        projectTool.promise();
      }
    }
  });
  return projectTool;
};
// 获取项目工具实例列表
function getProjectToolInstanceList(projectId, page, size) {
  var ref = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/projectToolInstance-api/byProject/" + projectId,
    data: {
      "page": page,
      "size": size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data);
        ref.promise();
      }
    },
    error: function (data) {
      ref.reject(data);
      ref.promise(data);
    }
  });
  return ref;
};
// 增加项目工具实例
function addProjectToolInstance(data) {
  var ref = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/projectToolInstance-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data);
        ref.promise();
      }
    },
    error: function (data) {
      ref.reject(data);
      ref.promise(data);
    }
  });
  return ref;
};
// 修改项目工具实例
function updateProjectToolInstance(projectToolInstanceId, name, description) {
  var ref = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/projectToolInstance-api/" + projectToolInstanceId,
    data: {
      "name": name,
      "description": description
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data);
        ref.promise();
      }
    },
    error: function (data) {
      ref.reject(data);
      ref.promise(data);
    }
  });
  return ref;
};
// 删除项目工具实例
function delProjectToolInstance(instanceId) {
  var ref = $.Deferred();
  $.ajax({
    type: "delete",
    url: PUBLIC_PM.prefixUrl + "/projectToolInstance-api/" + instanceId,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data);
        ref.promise();
      }
    },
    error: function (data) {
      ref.reject(data);
      ref.promise(data);
    }
  });
  return ref;
};
// tool typology
function getToolTypologyList(name) {
  var getToolTypologyList = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.toolPrefixUrl + "/" + name + "/meta.js",
    data: {},
    dataType: "json",
    success: function (data) {
      getToolTypologyList.resolve(data);
      getToolTypologyList.promise();
    }
  });
  return getToolTypologyList;
};
// project tool instance typology
function getProjectToolInstanceTypologyList(projectToolInstanceId, page, size) {
  var ref = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.toolPrefixUrl + "/projectToolInstanceTypology-api/" + projectToolInstanceId,
    data: {
      "page": page,
      "size": size
    },
    dataType: "json",
    success: function (data) {
      ref.resolve(data);
      ref.promise();
    }
  });
  return ref;
};
// 创建tool typology
function addToolTypology(data) {
  var addToolTypology = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/toolTypology-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        addToolTypology.resolve(data)
        addToolTypology.promise();
      } else {
        ShowMsg("工具不存在！");
      }
    },
    error: function () {
      ShowMsg("工具不存在！");
    }
  });
  return addToolTypology;
};
// 创建project tool instance typology
function addProjectToolInstanceTypology(data) {
  var ref = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/projectToolInstanceTypology-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data)
        ref.promise();
      } else {
        ShowMsg("工具不存在！");
      }
    },
    error: function () {
      ShowMsg("工具不存在！");
    }
  });
  return ref;
};
// 删除tool typology
function delToolTypology(data) {
  var delToolTypology = $.Deferred();
  $.ajax({
    type: "delete",
    url: PUBLIC_PM.prefixUrl + "/toolTypology-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        delToolTypology.resolve(data)
        delToolTypology.promise();
      }
    },
    error: function () {
      ShowMsg("记录不存在！");
    }
  });
  return delToolTypology;
};
// 删除project tool instance typology
function delProjectToolInstanceTypology(data) {
  var ref = $.Deferred();
  $.ajax({
    type: "delete",
    url: PUBLIC_PM.prefixUrl + "/projectToolInstanceTypology-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        ref.resolve(data)
        ref.promise();
      }
    },
    error: function () {
      ShowMsg("记录不存在！");
    }
  });
  return ref;
};
// ******tool  end
// ******typology  start
//ajax导入文件 typology配置文件
function imporFile($file) {
  var def = $.Deferred();
  $.ajax({
    type: "POST",
    url: PUBLIC_PM.prefixUrl + "/typology-api/importForProject/" + projectId,
    data: $file,
    dataType: "json",
    processData: false,
    contentType: false,
    // cache: false,
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        def.resolve(data)
        def.promise(data);
      }
    },
    error: function (data) {
      def.reject(data);
      def.promise(data);
    }
  });
  return def;
};
// 增加typology
function addTypology(data) {
  var addTypology = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/typology-api/",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        addTypology.resolve(data)
        addTypology.promise();
      }
    }
  });
  return addTypology;
};
// 修改typology
function updateTypology(data) {
  var updateTypology = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/typology-api/update",
    data: JSON.stringify(data),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        updateTypology.resolve(data)
        updateTypology.promise();
      }
    }
  });
  return updateTypology;
};
// 删除标注
function deleteTypology(typologyId) {
  var deleteTypology = $.Deferred();
  $.ajax({
    type: "post",
    url: PUBLIC_PM.prefixUrl + "/typology-api/" + typologyId,
    data: {},
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        deleteTypology.resolve(data)
        deleteTypology.promise();
      }
    }
  });
  return deleteTypology;
};
// 列出项目的typology
function typologyByProject(projectId) {
  var typologyByProject = $.Deferred();
  $.ajax({
    type: "get",
    async: false,
    url: PUBLIC_PM.prefixUrl + "/typology-api/byProject/" + projectId + "?page=0&size=10000",
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        typologyByProject.resolve(data)
        typologyByProject.promise();
      }
    },
    error: function (data) {
      typologyByProject.reject(data)
      typologyByProject.promise(data);
    }
  });
  return typologyByProject;
};
// 根据父获取子文档类型
function typologyByParent(parentId, projectId, page, size) {
  size = size || 200;
  page = page || 0;
  var typologyByParent = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/typology-api/byParent/" + parentId,
    data: {
      "projectId": projectId,
      "page": page,
      "size": size
    },
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        typologyByParent.resolve(data.content)
        typologyByParent.promise();
      }
    }
  });
  return typologyByParent;
};
// 获取当前类型信息
function typologyData(typologyId) {
  var typologyData = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/typology-api/" + typologyId,
    data: {},
    // contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        typologyData.resolve(data.content)
        typologyData.promise();
      }
    }
  });
  return typologyData;
}
// ******typology  end
// annotation  start
function getAnnotationByproject(projectId, page, size) {
  var getAnnotationByproject = $.Deferred();
  $.ajax({
    type: "get",
    url: PUBLIC_PM.prefixUrl + "/annotation-api/byProject/" + projectId + "?page=" + page + "&size=" + size,
    data: {},
    dataType: "json",
    success: function (data) {
      if (data.status == "STATUS_SUCCESS") {
        getAnnotationByproject.resolve(data.content)
        getAnnotationByproject.promise();
      }
    },
    error: function (data) {
      getAnnotationByproject.reject(data)
      getAnnotationByproject.promise(data);
    }
  });
  return getAnnotationByproject;
}
// 项目下的标注annotation
// annotation  end
//检索页面-start
//ajax对文档进行检索
function ajaxSearchForDocuments(ajaxPage, pageSize, $query, $projectId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/search-api/forDocuments';
  $.ajax({
    url: url,
    type: "GET",
    data: {
      'query': $query,
      'projectId': $projectId,
      'page': ajaxPage, //第几页
      'size': pageSize, //每页几条
      'sort': 'id'//id排序
    },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
      isClick = true;
    }
  });
  return def;
};
//ajax对标注进行检索
function ajaxSearchForAnnotations(ajaxPage, pageSize, $query, $projectId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/search-api/forAnnotations';
  $.ajax({
    url: url,
    type: "GET",
    data: {
      'query': $query,
      'projectId': $projectId,
      'page': ajaxPage, //第几页
      'size': pageSize, //每页几条
      'sort': 'id'//id排序
    },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
    }
  });
  return def;
};
//ajax对标注类型进行检索
function ajaxSearchForTypologies(ajaxPage, pageSize, $query, $projectId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/search-api/forTypologies';
  $.ajax({
    url: url,
    type: "GET",
    data: {
      'query': $query,
      'projectId': $projectId,
      'page': ajaxPage, //第几页
      'size': pageSize, //每页几条
      'sort': 'id'//id排序
    },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS' || dataList.status == 'STATUS_FAIL') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
    }
  });
  return def;
};
//ajax获取文档全部信息-任务数量
function ajaxDocumentsMassage($documentId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/document-api/' + $documentId;
  $.ajax({
    url: url,
    type: "GET",
    // data: {
    // },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
      if (dataList.status == 'STATUS_FAIL') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
    }
  });
  return def;
};
//ajax根据id列出Typeology全部信息
function ajaxTypeologyMassage($typologyId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/typology-api/' + $typologyId;
  $.ajax({
    url: url,
    type: "GET",
    // data: {
    // },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      } else if (dataList.status == 'STATUS_FAIL') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
    }
  });
  return def;
};
//ajax列出所有的Typology通过ParentId全部信息-获取子类型
function ajaxTypeologyParentMassage($ParentId, $projectId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/typology-api/byParent/' + $ParentId;
  $.ajax({
    url: url,
    type: "GET",
    data: {
      'projectId': $projectId
    },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
    }
  });
  return def;
};
//ajax列出Typeology全部信息-通过projectId -获取文章数量
function ajaxTypeologyMassageByProjectId($projectId) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/typology-api/byProject/' + $projectId;
  $.ajax({
    url: url,
    type: "GET",
    // data: {
    //   'projectId': $projectId
    // },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data)
      def.promise(data);
    },
    complete: function () {
    }
  });
  return def;
};
//检索页面-end
//统计页面-start
//ajax根据项目id，获取任务数量
function taskMyTaskForProject($projectId, page, size) {
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/task-api/myTaskForProject/' + $projectId + "?page=" + page + "&size=" + size;
  $.ajax({
    url: url,
    type: "GET",
    // data: {
    //   'projectId': $projectId
    // },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    complete: function () {
      isClick = true;
      $('.loading-box').hide();
    }
  });
  return def;
};
//主要用于统计,对日志进行检索,【文档、用户】类型，获取标注
function ajaxSearchForLogGetAnnotation(ajaxPage, pageSize, $projectId, $startTime, $endTime) {
  var $dataType = $('#result-table-toolbar').attr('data-type');
  var $documentIds = [];
  var $userIds = [];
  // var $typologyIds = selectedTypologyListIdArr;
  var $typologyIds = '';
  // var $startTime = '1900-01-01 00:00:00';
  // var $endTime = '2020-08-26 23:59:59';
  //判断对什么检索：文档，成员
  if ($dataType == 'document') {
    $documentIds = listSelectIdArr;
    listSelectUserIdArr = [];
  } else if ($dataType == 'member') {
    $userIds = listSelectIdArr
    $documentIds = [];
  }
  //ajax参数字符串拼接typologyIds
  for (var i = 0; i < selectedTypologyListIdArr.length; i++) {
    $typologyIds += 'typologyIds=' + selectedTypologyListIdArr[i];
    if (i < selectedTypologyListIdArr.length - 1) {
      $typologyIds += '&';
    }
  }
  //东八区影响，时间差8小时，前端手动添加8小时
  // $startTime = '2020-06-15 02:50:20';
  // $endTime = '2020-06-15 10:50:20';
  var def = $.Deferred();
  var url = PUBLIC_PM.prefixUrl + '/annotation-api/statistic/' + $projectId + '?' + $typologyIds;
  $.ajax({
    url: url,
    type: "GET",
    data: {
      'documentIds': $documentIds,//可传空，为全部
      'userIds': $userIds,//可以传空，为全部
      // 'typologyIds': $typologyIds,//必传
      'start': $startTime,
      'end': $endTime,
      'page': ajaxPage, //第几页
      'size': pageSize, //每页几条
      'sort': 'createTime'//id排序
    },
    dataType: "json",
    success: function (dataList) {
      // console.log(data);
      if (dataList.status == 'STATUS_SUCCESS') {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      } else {
        var dataList = dataList;
        def.resolve(dataList);
        def.promise(dataList);
      }
    },
    error: function (data) {
      def.reject(data);
      def.promise(data);
    },
    complete: function () {
      isClick = true;
      // $('.loading-box').hide();
    }
  });
  return def;
};
//统计页面-end
// 提示语
function ShowTip(tip, tipType) {
  var $tip = $('#tip');
  // if ($tip.length == 0) {
  $tip = $('<strong id="tip" class="selfTipBox" style=""></strong>');
  $('body').append($tip);
  // }
  $tip.stop(true).text(tip).prop('class', 'selfTipBox')
  // .prop('class', 'ShowMsg ShowMsg-' + tipType)
  // .fadeIn(500).delay(1000).fadeOut(500);
  // $tip.animate({},1000,function (){
  //   $tip.remove();
  // })
  $tip.animate({
    'position': 'absolute',
    'top': '30%',
    'left': '50%',
    'transform': 'translate(-50%, -50%)',
    'line-height': ' 40px',
    'background': '#ccc',
    'color': '#000',
    'padding': '5px 10px',
    'border-radius': '3px',
    'z-index': '9999',
    'opacity': '0',
  }, 2500, function () {
    // $(this).remove();
  })
};
function ShowMsg(msg) {
  ShowTip(msg, 'info');
};
